<html>
<head><meta charset="utf-8"><title>associated consts const wf · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html">associated consts const wf</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205278595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278595">(Jul 28 2020 at 19:18)</a>:</h4>
<p>.</p>



<a name="205278617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278617">(Jul 28 2020 at 19:18)</a>:</h4>
<p>somewhat building on <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20wf.20bounds.20implementation">https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/const.20wf.20bounds.20implementation</a></p>



<a name="205278655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278655">(Jul 28 2020 at 19:19)</a>:</h4>
<p>Associated const are currently not checked for const well formedness, so the following is allowed:</p>



<a name="205278665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278665">(Jul 28 2020 at 19:19)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">64</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205278784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278784">(Jul 28 2020 at 19:20)</a>:</h4>
<p>So <a href="https://github.com/rust-lang/rust/issues/74877">#74877</a> implements <code>min_const_generics</code> and currently also restricts const generics from showing up in associated constants</p>



<a name="205278866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278866">(Jul 28 2020 at 19:21)</a>:</h4>
<p>imo it is very desirable to force associated consts to be const wf</p>



<a name="205278965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278965">(Jul 28 2020 at 19:22)</a>:</h4>
<p>The two questions are:</p>



<a name="205278984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205278984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205278984">(Jul 28 2020 at 19:22)</a>:</h4>
<p>Do we want to check const wf of associated consts? (imo yes)</p>



<a name="205279002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205279002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205279002">(Jul 28 2020 at 19:22)</a>:</h4>
<p>How do we implement this?</p>



<a name="205279932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205279932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205279932">(Jul 28 2020 at 19:30)</a>:</h4>
<p>Wait, we probably can just propagate these upwards, as the value of associated consts should be part of the public interface of an impl</p>



<a name="205280040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280040">(Jul 28 2020 at 19:31)</a>:</h4>
<p>at this point we can't really force them be const wf though, as doing so would be a breaking change (i.e. <code>Foo</code> would suddenly stop being implemented for <code>()</code>)</p>



<a name="205280091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280091">(Jul 28 2020 at 19:31)</a>:</h4>
<p>So we probably should restrict const wf to consts used as part of the type system</p>



<a name="205280121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280121">(Jul 28 2020 at 19:32)</a>:</h4>
<p>at which point we will require a const wf bound on <code>Foo::ASSOC</code> anyways</p>



<a name="205280511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280511">(Jul 28 2020 at 19:35)</a>:</h4>
<p>so... we don't have to do anything except require wf for all constants used in type systems?</p>



<a name="205280542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280542">(Jul 28 2020 at 19:35)</a>:</h4>
<p>probably, it is unfortunate though :/</p>



<a name="205280638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280638">(Jul 28 2020 at 19:36)</a>:</h4>
<p>it's not too bad, we can add warnings suggesting the addition of wf bounds on the impls which will then cause the breakage</p>



<a name="205280738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205280738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205280738">(Jul 28 2020 at 19:37)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="p">]</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Assoc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="c1">// ^ requires wf bound</span>

<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="c1">// ^ does not require wf bound, just breaks for `[u8; 0]`</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205281033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205281033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205281033">(Jul 28 2020 at 19:40)</a>:</h4>
<p>What I am now still unsure of is if we want to restrict associated consts to just <code>N</code> and <code>{ N }</code> for <code>min_const_generics</code></p>



<a name="205281173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205281173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205281173">(Jul 28 2020 at 19:41)</a>:</h4>
<p>That restriction doesn't really make sense if we ignore const wf for associated consts, so we could just not restrict them</p>



<a name="205290362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290362">(Jul 28 2020 at 21:00)</a>:</h4>
<p>Hmm</p>



<a name="205290412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290412">(Jul 28 2020 at 21:01)</a>:</h4>
<p>It might be technically breaking, but how likely it is that it is breaking some crate somewhere?</p>



<a name="205290429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290429">(Jul 28 2020 at 21:01)</a>:</h4>
<p>(I ask unironically)</p>



<a name="205290440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290440">(Jul 28 2020 at 21:01)</a>:</h4>
<p>So forbidding <code>std::mem::size_of::&lt;T&gt;()</code> is quite breaking</p>



<a name="205290508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290508">(Jul 28 2020 at 21:02)</a>:</h4>
<p>Wait</p>



<a name="205290527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290527">(Jul 28 2020 at 21:02)</a>:</h4>
<p>Why does that break?</p>



<a name="205290538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290538">(Jul 28 2020 at 21:02)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="205290589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290589">(Jul 28 2020 at 21:03)</a>:</h4>
<p>So using const wf bounds here, <code>T</code> would only implement <code>Foo</code> if <code>ConstEvaluatable(std::mem::size_of::&lt;T&gt;())</code></p>



<a name="205290598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290598">(Jul 28 2020 at 21:03)</a>:</h4>
<p>And that associated const is currently legal?</p>



<a name="205290615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290615">(Jul 28 2020 at 21:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="212698">Félix Fischer</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/associated.20consts.20const.20wf/near/205290598">said</a>:</p>
<blockquote>
<p>And that associated const is currently legal?</p>
</blockquote>
<p>yeah</p>



<a name="205290629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290629">(Jul 28 2020 at 21:03)</a>:</h4>
<p>Fuuuuck xD</p>



<a name="205290636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290636">(Jul 28 2020 at 21:03)</a>:</h4>
<p>Okay</p>



<a name="205290643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290643">(Jul 28 2020 at 21:03)</a>:</h4>
<p>I get it now</p>



<a name="205290646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290646">(Jul 28 2020 at 21:03)</a>:</h4>
<p>Hm</p>



<a name="205290707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290707">(Jul 28 2020 at 21:04)</a>:</h4>
<p>Could we add a lint asking for the bound?</p>



<a name="205290727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290727">(Jul 28 2020 at 21:04)</a>:</h4>
<p>And deprecate it when the next Edition comes?</p>



<a name="205290753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290753">(Jul 28 2020 at 21:04)</a>:</h4>
<p>(Deprecate the older way w/o wf bounds)</p>



<a name="205290850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290850">(Jul 28 2020 at 21:05)</a>:</h4>
<p>lint seems like a good idea <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span> Not sure how easy changing the behavior on an edition boundary will be</p>



<a name="205290910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290910">(Jul 28 2020 at 21:06)</a>:</h4>
<p>but that would have to wait until at least 2024 anyways, so we'll see more then</p>



<a name="205290966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205290966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205290966">(Jul 28 2020 at 21:07)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span>🏻👍🏻</p>



<a name="205291062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205291062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205291062">(Jul 28 2020 at 21:08)</a>:</h4>
<p>uuuuuuuuuu~~~~~~</p>



<a name="205291065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205291065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205291065">(Jul 28 2020 at 21:08)</a>:</h4>
<p>unicode support</p>



<a name="205291078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205291078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205291078">(Jul 28 2020 at 21:08)</a>:</h4>
<p><a href="/user_uploads/4715/vGqdhp5dN0ySZQVDGGv28jdQ/Screenshot-from-2020-07-28-23-08-18.png">Screenshot-from-2020-07-28-23-08-18.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/vGqdhp5dN0ySZQVDGGv28jdQ/Screenshot-from-2020-07-28-23-08-18.png" title="Screenshot-from-2020-07-28-23-08-18.png"><img src="/user_uploads/4715/vGqdhp5dN0ySZQVDGGv28jdQ/Screenshot-from-2020-07-28-23-08-18.png"></a></div>



<a name="205291122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205291122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205291122">(Jul 28 2020 at 21:09)</a>:</h4>
<p>Hahahahaha</p>



<a name="205291171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205291171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205291171">(Jul 28 2020 at 21:09)</a>:</h4>
<p>It renders the first one like that for me, and the second one like the colored hand (I sent two, like so: <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span>)</p>



<a name="205361793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/205361793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#205361793">(Jul 29 2020 at 14:13)</a>:</h4>
<p>For me it is thumbs up + colored block + colored thumbs up.</p>
<p><a href="/user_uploads/4715/Swbcn18B0j1QCXBElar7FRsQ/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/Swbcn18B0j1QCXBElar7FRsQ/image.png" title="image.png"><img src="/user_uploads/4715/Swbcn18B0j1QCXBElar7FRsQ/image.png"></a></div>



<a name="212044948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212044948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212044948">(Oct 02 2020 at 08:14)</a>:</h4>
<p><span class="user-mention" data-user-id="121053">@varkor</span>  re assoc wf, this was the only discussion we had about that for now.</p>
<p>I think the current summary is that we just allow arbitrary expressions using const parameters in associated consts as we already do so for type params.</p>
<p>Meaning that the following code is valid</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="n">TraitFoo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Bar</span><span class="o">&lt;</span><span class="n">N</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">N</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="c1">// ...</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212045022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212045022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212045022">(Oct 02 2020 at 08:15)</a>:</h4>
<p>I guess that once <code>const_evaluatable_checked</code> is available on stable we can then add warnings here recommending to add the associated consts as a bound to the trait impl</p>



<a name="212045201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212045201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212045201">(Oct 02 2020 at 08:17)</a>:</h4>
<p>One of the big concerns here is that using associated consts which evaluate to an error is not allowed, even if they are used in dead code</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Foo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="n">ASSOC</span>: <span class="kt">usize</span> <span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="n">std</span>::<span class="n">mem</span>::<span class="n">size_of</span>::<span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Foo</span>::<span class="o">&lt;</span><span class="kt">u64</span><span class="o">&gt;</span>::<span class="n">ASSOC</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="212045284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212045284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212045284">(Oct 02 2020 at 08:18)</a>:</h4>
<p>so we have similar post monomorphization errorsv we would get for <code>[u8; 2 - N]</code>, except that these are already possible on stable</p>



<a name="212045346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212045346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212045346">(Oct 02 2020 at 08:19)</a>:</h4>
<p>and I am really not completely sold that there is a difference between associated consts and consts used in types in that regard, meaning that we would make this situation worse for the sake of consistency.</p>



<a name="212075196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212075196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212075196">(Oct 02 2020 at 13:38)</a>:</h4>
<p>I agree there ought not to be a distinction.</p>



<a name="212075302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212075302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212075302">(Oct 02 2020 at 13:39)</a>:</h4>
<p>It's a bit of a mess regarding what's currently permitted.</p>



<a name="212075401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212075401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212075401">(Oct 02 2020 at 13:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/associated.20consts.20const.20wf/near/212045022">said</a>:</p>
<blockquote>
<p>I guess that once <code>const_evaluatable_checked</code> is available on stable we can then add warnings here recommending to add the associated consts as a bound to the trait impl</p>
</blockquote>
<p>Doing this for all these sorts of cases seems the best way forwards, I agree.</p>



<a name="212131877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/212131877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matt1992 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#212131877">(Oct 02 2020 at 21:36)</a>:</h4>
<p>As somebody who has used associated constants a ton since they were stabilized, I've <del>never seen post-monomorphization errors</del>(correction: I've seen them while developing features, but not when using them AFAIR), so requiring users to write bounds to avoid them seems like an extreme measure to me.</p>



<a name="223772496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/223772496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#223772496">(Jan 23 2021 at 20:03)</a>:</h4>
<p>i am currently thinking that it might be better to move the const wf checks to the usage site instead for associated consts and for generic constants if we ever add them</p>



<a name="223772569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/223772569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#223772569">(Jan 23 2021 at 20:04)</a>:</h4>
<p>i should take some time to write down the way i currently imagine const wf to work</p>



<a name="223772586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/associated%20consts%20const%20wf/near/223772586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/associated.20consts.20const.20wf.html#223772586">(Jan 23 2021 at 20:05)</a>:</h4>
<p>will try doing so once project cg has its own repo</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>